<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="dashboard/header :: header"></head>
<body>
	<div layout:fragment="content">
		<div class="container-fluid content-main">
			<div class="animated fadeIn">
				<div class="row">
					<!-- /.col-->
					<div class="col-sm-12">
						<div class="card">
							<div class="card-body">

								<form class="form-horizontal" id="addForm" style="float:left;width:100%">
								
									<input type="hidden" name="formToken" th:value="${session.formToken}" />
								
									<div class="form-group row margin-right-0">
										<label class="col-md-3 col-form-label" for="text-input">所属应用</label>
										<div class="col-md-12">
											<input class="form-control" id="text-input" type="text" onclick="showApplication()" name="applicationIdLabel" readonly="readonly" style="cursor: pointer" placeholder="所属应用">
											<input type="hidden" name="applicationId"  />
										</div>
									</div>
									<div class="form-group row margin-right-0">
										<label class="col-md-3 col-form-label" for="text-input">上级菜单</label>
										<div class="col-md-12">
											<input class="form-control" id="text-input"  type="text" style="cursor:pointer" readonly="readonly" onclick="showResourceParent()"  name="resourceParentLabel" placeholder="上级菜单">
											<input type="hidden" name="resourceParent"  />
										</div>
									</div>
									<div class="form-group row margin-right-0">
										<label class="col-md-3 col-form-label" for="text-input">菜单名称</label>
										<div class="col-md-12">
											<input class="form-control" id="text-input" type="text"
												name="resourceName" placeholder="菜单名称">
										</div>
									</div>
									<div class="form-group row margin-right-0">
										<label class="col-md-3 col-form-label" for="email-input">菜单链接</label>
										<div class="col-md-12">
											<input class="form-control" id="email-input" type="email"
												name="resourceLink" placeholder="菜单链接">
										</div>
									</div>
									<!-- 
									<div class="form-group row margin-right-0">
										<label class="col-md-3 col-form-label" for="email-input">菜单图标</label>
										<div class="col-md-12">
											<input class="form-control" id="email-input" type="email"
												name="resourceIcon" placeholder="菜单图标">
										</div>
									</div>
									 -->
								
									<div class="form-group row">
										<label class="col-md-3 col-form-label" for="email-input">菜单图标</label>
										<div class="col-md-9">
											<span class="form-control" id="resourceIconLabel" style="cursor:pointer;" readonly="readonly" onclick="showIcons()">菜单图标</span>
											<input type="hidden" id="resourceIcon" name="resourceIcon" />
										</div>
									</div>	
									
									<div class="form-group row margin-right-0">
										<label class="col-md-3 col-form-label" for="email-input">菜单类型</label>
										<div class="col-md-12">
											<select class="form-control" id="menuType" name="menuType">
												<option value="9">菜单</option>
												<option value="1" selected>按钮</option>
											</select>
										</div>
									</div>
									<div class="form-group row margin-right-0">
										<label class="col-md-3 col-form-label" for="email-input">状态</label>
										<div class="col-md-12">
											<self:dictionary type="common_status" name="hasStatus" />	
										</div>
									</div>
								</form>

							</div>
							
							<!-- 
							<div class="card-footer">
								<button class="btn btn-primary" style="float: right" onclick="save()" type="button">保存</button>
							</div>
							-->

						</div>
					</div>
					<!-- /.col-->
				</div>
			</div>
		</div>

	</div>

	<footer th:replace="dashboard/footer :: footer"></footer>

	<script type="text/javascript">
		// 保存操作
		/*
		function save() {
			console.log('save');
			$("#addForm").ajaxSubmit({
				url : ctx+"boot/platform/menus/save",
				type : "POST",
				headers : {
					'Content-Type' : 'application/x-www-form-urlencoded' //multipart/form-data;boundary=--xxxxxxx   application/json
				},
				success : function(data) {
					if (data.code == 200) {
						layer.msg("操作成功!");
					} else {
						layer.alert(data.message);
					}
				}
			});
		}
		*/
		
		function submitHandler() {
			$.operate.save(ctx+"boot/platform/menus/save" , $('#addForm').serialize());
	    }
	
		function showIcons(){
			var index = layer.open({
			type : 2,
			title : false , //'菜单管理',
			closeBtn:0 ,
			shadeClose : true,
			shade : 0.8,
			area : [ '100%', '100%' ],
			content : ctx+'pages/boot/platform/application/icons?id=1' , 
			btn: ['确认', '取消'] , 
			yes: function(index, layero){
				
				console.log("index = " + index + " layero = " + layero) ; 
				var selectResourceParentNode = $(layero).find("iframe")[0].contentWindow.document.getElementById("selectResourceParentNode")
				
				var resourceName = $(selectResourceParentNode).attr("data-name") ; 	
				var id = $(selectResourceParentNode).attr("data-id") ; 	
				
				console.log("selectResourceId = " + id + " , selectResourceName = " + resourceName) ;
				
				$("span#resourceIconLabel").html('<i class="'+resourceName+'" aria-hidden="true"></i>') ; 
				$("input#resourceIcon").val(id) ; 
				
				layer.close(index) ; 
				
			 }	
		   }) ; 
		} 
		
		function showResourceParent(){
			var index = layer.open({
				type : 2,
				title : false , //'菜单管理',
				closeBtn:0 ,
				shadeClose : true,
				shade : 0.8,
				area : [ '100%', '100%' ],
				content : ctx+'boot/platform/menus/parents?id=1' , 
				btn: ['确认', '取消'] , 
				yes: function(index, layero){
					console.log("index = " + index + " layero = " + layero) ; 
					var selectResourceParentNode = $(layero).find("iframe")[0].contentWindow.document.getElementById("selectResourceParentNode")
					
					var resourceName = $(selectResourceParentNode).attr("data-resourceName") ; 	
					var id = $(selectResourceParentNode).attr("data-id") ; 	
					
					console.log("selectResourceId = " + id + " , selectResourceName = " + resourceName) ;
					
					$("input[name=resourceParentLabel]").val(resourceName) ; 
					$("input[name=resourceParent]").val(id) ; 
					
					layer.close(index) ; 
			 	}
			});		
		}
		
		function showApplication(){
			var index = layer.open({
				type : 2,
				title : false , //'菜单管理',
				closeBtn:0 ,
				shadeClose : true,
				shade : 0.8,
				area : [ '100%', '100%' ],
				content : ctx+'boot/platform/application/select' , 
				btn: ['确认', '取消'] , 
				yes: function(index, layero){
					console.log("index = " + index + " layero = " + layero) ; 
					var selectResourceParentNode = $(layero).find("iframe")[0].contentWindow.document.getElementById("selectResourceParentNode")
					
					var resourceName = $(selectResourceParentNode).attr("data-applicationName") ; 	
					var id = $(selectResourceParentNode).attr("data-id") ; 	
					
					console.log("applicationId = " + id + " , applicationIdLabel = " + resourceName) ;
					
					$("input[name=applicationIdLabel]").val(resourceName) ; 
					$("input[name=applicationId]").val(id) ; 
					
					layer.close(index) ; 
			 	}
			});		
		}
	</script>

</body>
</html>
